package com.pinganfu.mock.test;

import java.io.BufferedReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;





import net.sf.json.JSON;
import net.sf.json.xml.XMLSerializer;

import org.apache.http.client.HttpClient;
import org.apache.ibatis.scripting.xmltags.VarDeclSqlNode;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.XML;
import org.springframework.http.HttpMethod;

public class test1 {
     
	/* 向指定URL发送GET方法的请求
    * 
    * @param url
    *            发送请求的URL
    * @param param
    *            请求参数，请求参数应该是 name1=value1&name2=value2 的形式。
    * @return URL 所代表远程资源的响应结果
    */
   public static String sendGet(String url, String param) {
       String result = "";
       BufferedReader in = null;
       try {
           String urlNameString = url + "?" + param;
           URL realUrl = new URL(urlNameString);
           // 打开和URL之间的连接
           URLConnection connection = realUrl.openConnection();
           // 设置通用的请求属性
           connection.setRequestProperty("accept", "*/*");
           connection.setRequestProperty("connection", "Keep-Alive");
           connection.setRequestProperty("user-agent",
                   "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
           // 建立实际的连接
           connection.connect();
           // 获取所有响应头字段
           Map<String, List<String>> map = connection.getHeaderFields();
           // 遍历所有的响应头字段
           for (String key : map.keySet()) {
               System.out.println(key + "--->" + map.get(key));
           }
           // 定义 BufferedReader输入流来读取URL的响应
           in = new BufferedReader(new InputStreamReader(
                   connection.getInputStream()));
           String line;
           while ((line = in.readLine()) != null) {
               result += line;
           }
       } catch (Exception e) {
           System.out.println("发送GET请求出现异常！" + e);
           e.printStackTrace();
       }
       // 使用finally块来关闭输入流
       finally {
           try {
               if (in != null) {
                   in.close();
               }
           } catch (Exception e2) {
               e2.printStackTrace();
           }
       }
       return result;
   }
	
	
	
	public static void main(String[] args) throws Exception {
		Map<String,Object> aaa = new HashMap<String,Object>();
		aaa.put("json", "123");
		
		String sh = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>"
				+ "<reqId>合作伙伴编号</reqId>"
				+ "<serviceId>1000010000000070</serviceId>"
				+ "<bizdata>"
				+ "<sign>"
				+ "<idx>00</idx>"
				+ "<value>签名值</value>"
				+ "</sign>"
				+ "<data>"
				+ "<encode>utf-8</encode>"
				+ "<LPMS_Pionts>"
				+ "<Request>"
				+ "<PropertySet>"
				+ "<SiebelMessage>"
				+ "<ProcessName>PA UpdTicket Process</ProcessName>"
				+ "<TerminalID></TerminalID>"
				+ "<param></param>"
				+ "<FirmID></FirmID>"
				+ "<StoreID></StoreID>"
				+ "<Operation>UpdTicketOp</Operation>"
				+ "<Method>UpdTicket</Method>"
				+ "<TransactionType></TransactionType>"
				+ "<trip>"
				+ "<departure>TAO</departure>"
				+ "<departureCn>青岛</departureCn>"
				+ "<destination>PVG</destination>"
				+ "<destinationCn>上海浦东</destinationCn>"
				+ "<ticketNo>7815895715828</ticketNo>"
				+ "<passagerName>孙勇</passagerName>"
				+ "<sequence>1</sequence>"
				+ "<usageStatus>USED/FLOWN/</usageStatus>"
				+ "<usageStatusCn>已使用</usageStatusCn>"
				+ "</trip>"
				+ "<trip></trip>"
				+ "</SiebelMessage>"
				+ "</PropertySet>"
				+ "</Request>"
				+ "</LPMS_Pionts>"
				+ "</data>"
				+ "</bizdata></root>";
		
		// String sr=HttpClientService.post("http://10.59.32.17:35100/cma-web/services/institutionalTransFacadeRemote", "{"":""}");
	  //  String sr = sendGet("http://localhost:8080/TestManagerPlatform/jekinsSum/getJenkinsSumList", "") ;
		
		//System.out.println("加密数据："+sr);
	        
	       //String sr2=HttpClientService.post("http://10.59.32.13:32800/caps/aesdec.do", "7i0XI2mxdFGTMVP+zJeL5p3g676uqF2Pyohuugm5Zyk=");
	      //System.out.println("解密数据："+sr2);
		//String sr=HttpClientService.post("http://10.59.33.49:8080/MockPlatform/Synchronous/https/jifenTesting", "{	\"reqId\":\"P1000520\",	\"traceNo\":\"zm_3999\",  	\"memberId\":\"010100142594620\",	\"bizCode\":\"0903008\",	\"baseAmount\":\"5000000000\",	\"bizVerifyTime\":\"\",	\"expiredTime\":\"2016-09-28 10:00:00\",	\"comments\":\"联调测试\",    \"costOrg\":\"成本部门\",    \"wltChannel\":\"万里通渠\",    \"resv\":\"6,11\",    \"orgOrderNum\":\"\"} ");
		//String sr=HttpClientService.post("http://localhost:8080/MockPlatform/Synchronous/http/capstest", "{	\"reqId\":\"P1000520\",	\"traceNo\":\"zm_3999\",  	\"memberId\":\"010100142594620\",	\"bizCode\":\"0903008\",	\"baseAmount\":\"5000000000\",	\"bizVerifyTime\":\"\",	\"expiredTime\":\"2016-09-28 10:00:00\",	\"comments\":\"联调测试\",    \"costOrg\":\"成本部门\",    \"wltChannel\":\"万里通渠\",    \"resv\":\"6,11\",    \"orgOrderNum\":\"\"} ");
		String sr=HttpClientService.post("https://www.corporatetravel.ctrip.com/switchapi/platform.svc/rest/ticket", "{ \"appKey\":\"obk_test\", \"appSecurity\": \"obk_test\" }");
		
		System.out.println(sr);
		
		/*String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><document><request><head><version>V0.1</version><appid>2016032300001paf</appid><function>paf.medical.card.query</function><reqTime>20160518162429</reqTime><reqTimeZone>UTC+8</reqTimeZone><reqMsgId>COM201605181624296040000083</reqMsgId></head><body><out_order_no>COM201605181624296040000083</out_order_no><user_id>881434367015101101</user_id><user_card_type>1</user_card_type><user_card_no>320000199505125497</user_card_no><real_name>性能</real_name><bank_card_no>6230583253249002012</bank_card_no><extend_params></extend_params><medical_card_no></medical_card_no></body></request><signature>AptpfardoCflHPpfkhHyKPdtykKehLaJ1ShtvwYyIAqdywkgDAh0vMdPR/6Jg6eugcDFU0oIhGmLXafLLwBkCOOGY72J9/RQVbYZyBN/G2y9T4NbCXoMYD341r4vj+Vht7eSSaRkwFAU7vcpseJr2LnzpTxy0Wgv6hChbHfxCacRN33DAu6Czsb+NUnG60dljiS9U7u0EnbkV11dOO2V2jFI0mEF1wQdFr12ZqSllmqn4UEtn5rtwAga2IkXnKlzxvxVcKhGhK7VHMFueUjikaBCCVUv0/SY9FDKSJC3qUoJN+FwxlJLm569vZNO/jHAJ4eFXK298cZEu83vWEiLQg==</signature></document>";
		//String s = "<document>    <response>     <header>       <version>1.0.0</version>        <appid>2014000014442</appid>        <function>paf.medical.order.prepare</function>        <respTime>2014-10-01 01:00:00</respTime>        <respTimeZone>UTC 8</respTimeZone>        <reqMsgId>4dceda4e-3a16-4d38-a643-7812f8d264d6</reqMsgId>     </header>      <body>       <resultinfo>         <resultStatus>S</resultStatus>          <resultCode>SUCCESS</resultCode>       </resultinfo>        <medical_card_id></medical_card_id> 	       <medical_card_no>20200000002</medical_card_no>        <medical_card_validate_date>20170909</medical_card_validate_date>        <medical_card_status>active</medical_card_status>        <medical_card_type>finance</medical_card_type>        <bank_card_no>6230586902619381510</bank_card_no>        <out_user_account>dsfa@163.com</out_user_account>        <out_user_id>123000002</out_user_id>        <out_user_name>小黑</out_user_name>        <out_user_card_type>01</out_user_card_type>        <out_user_card_no>320106196012153772</out_user_card_no>        <social_card_no>100002</social_card_no>     </body>   </response>    <signature>SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS</signature> </document>";
		XMLSerializer xmlSerializer = new XMLSerializer();
		
		JSON json = xmlSerializer.read( xml ); 
		
		String string = json.toString();
		
		System.out.println(string);*/
		
		
		
	      
	}
	
	/*public static void ConvertXMLtoJSON()  {  
        //InputStream is = ConvertXMLtoJSON.class.getResourceAsStream("sample.xml");  
       String xml="{\"response\":{\"header\":{\"version\":\"1.0.0\",\"appid\":\"2014000014442\",\"function\":\"paf.medical.order.prepare\",\"respTime\":\"2014-10-01 01:00:00\",\"respTimeZone\":\"UTC 8\",\"reqMsgId\":\"4dceda4e-3a16-4d38-a643-7812f8d264d6\"},\"body\":{\"resultinfo\":{\"resultStatus\":\"S\",\"resultCode\":\"SUCCESS\"},\"medical_card_id\":[],\"medical_card_no\":\"20200000002\",\"medical_card_validate_date\":\"20170909\",\"medical_card_status\":\"active\",\"medical_card_type\":\"finance\",\"bank_card_no\":\"6230586902619381510\",\"out_user_account\":\"dsfa@163.com\",\"out_user_id\":\"123000002\",\"out_user_name\":\"小黑\",\"out_user_card_type\":\"01\",\"out_user_card_no\":\"320106196012153772\",\"social_card_no\":\"100002\"}},\"signature\":\"SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\"}";  
        //xml = IOUtils.toString(is); 
		  JSONObject jsonObj=new JSONObject(xml);
		  System.out.println(XML.toString(jsonObj));
		System.out.println(xml);  
		XMLSerializer xmlSerializer = new XMLSerializer();  
		JSON json = xmlSerializer.read(xml);  
		System.out.println(json.toString(1));  
    }  
      
    public static void main(String[] args) {  
        ConvertXMLtoJSON();  
    }  */
}
